<style>
	.category-button{font-size:0.9em;font-weight:bold;cursor:pointer}
	.category-button:hover{}
</style>

<div class="section">
	<div class="section-title">Doctor Management</div>
	<div class="content">
   		<table>
        	<thead>
            	<tr>
                	<th>Doctor name</th>
                    <th><?php echo $this->document->text['text_control']?></th>
                </tr>
            </thead>
        	<tbody>
<?php
	foreach($doctors as $item)
    {
?>
        		<tr>
            		<td>
                    	<a href="?route=soft/product&userid=<?php echo $item['userid']?>"><?php echo $item['fullname']?></a>
                    </td>
                    <td align="center">
                        <a class="category-button" onclick="editDoctor('<?php echo $item['userid']?>')"><?php echo $this->document->text['button_edit']?></a> 
                        <a class="category-button" onclick="removeDoctor('<?php echo $item['userid']?>')">Remove</a> 
                	</td>
            	</tr>
<?php
	}
?>
			</tbody>
        </table>
		<a class="button" onclick="addDoctor('')">Add doctor</a>
        <form id="fdoctor" method="post" style="display:none">
        	<p>
            	
                <input type="hidden" class="text" id="userid" name="userid" />
                <input type="hidden" class="text" id="status" name="status" />
                <br />
                <label><?php echo $this->document->text['text_username']?></label><br />
                <input type="text" class="text" id="username" name="username" /><br />
                <label>Doctor name</label><br />
                <input type="text" class="text" id="fullname" name="fullname" /><br />
                <label><?php echo $this->document->text['text_email']?></label><br />
                <input type="text" class="text" id="email" name="email" /><br />
                <label><?php echo $this->document->text['text_address']?></label><br />
                <input type="text" class="text" id="address" name="address" /><br />
                <label><?php echo $this->document->text['text_phone']?></label><br />
                <input type="text" class="text" id="phone" name="phone" /><br />&nbsp;
                <a class="button" onclick="saveDoctor()">Save</a>
            </p>
        </form>
    </div>
</div>
<script language="javascript">
function saveDoctor()
{
	if( $("#fullname").val() !="")
	{
		$.blockUI({ message: "<h1>Please wait...</h1>" }); 
		$.post("?route=soft/doctor/save", 
			   $("#fdoctor").serialize(),
			   function(data)
			   {
				   if(data == "true")
				 	 window.location.reload();
					else
					{
						$.unblockUI();
					}
				}
			   );
		
	}
}
function addDoctor(parent)
{
	$.blockUI({ message: "<h1>Please wait...</h1>" }); 
	$('#fdoctor').show('slow');
	$('#userid').val('');
	$('#status').val('');
	$("#username").val('');
	$("#fullname").val('');
	$("#email").val('');
	$("#address").val('');
	$("#phone").val('');
	$.unblockUI(); 
}
function editDoctor(userid)
{
	$.blockUI({ message: "<h1>Please wait...</h1>" }); 
	$.getJSON("?route=soft/doctor/getDoctor&userid="+userid, 
			function(data) 
			{
				//alert(data.subimage.imagepreview);
				
				$("#userid").val(data.user.userid);
				$("#status").val(data.user.status);
				$("#username").val(data.user.username);
				$("#fullname").val(data.user.fullname);
				$("#email").val(data.user.email);
				$("#address").val(data.user.address);
				$("#phone").val(data.user.phone);
				$.unblockUI(); 
				$('#fdoctor').show('slow');
			});
}

function removeDoctor(userid)
{
	var answer = confirm("Are you want to delete")
	if(answer)
		$.ajax({
			url: "?route=soft/doctor/removeDoctor&userid="+userid,
			cache: false,
			success: function(html){
				if(html=="true")
					window.location.reload();
				else
					alert("Can't delete because this category contained some products!")
			}
		});
}
</script>